# Japan Graphs Code
# JBS 11/08/2009

setwd("/Users/jonslapin/Documents/papers and diss/Japan/new data and scripts Sept 19 08")

dta<-read.csv("for_10Aug09_documents.csv", sep=" ", header=T)

names<-strsplit(rownames(dta),"\\.")

party <- rep(0,length=names)
year<- rep(0,length=names)

for (i in 1:length(names)) {
      party[i]<-names[[i]][1]
      year[i] <-names[[i]][2]
}

dtalong <- cbind(party,year,dta)
attach(dtalong)
dtalong <- dtalong[,-c(4)]

dtawide<-reshape(dtalong,v.names="omega",idvar="party",direction="wide",timevar="year")

x<-seq(1,8,1)
y<-seq(-1.5,1.5,length.out=8)

xlab<-c("60-64","65-69","71-72","76-79","80-83","86-90","93-95","96-98")

colvec<-rainbow(n=6,start=0.7,end=0.15)



pdf("Foreign_10Aug09.pdf")
plot(x,y,type="n",main="Foreign Policy", xlab="Years", ylab="Party Position", xaxt="n")
axis(1,at=x,labels=xlab)
lines(x,dtawide[1,2:ncol(dtawide)],lty=3, lwd=2.5, col=colvec[3])
lines(x,dtawide[2,2:ncol(dtawide)],lty=1,lwd=2.5,col=colvec[1])
lines(x,dtawide[3,2:ncol(dtawide)],lty=2,lwd=2.5,col=colvec[2])
lines(x,dtawide[4,2:ncol(dtawide)],lty=1,lwd=2.5,col=colvec[5])
lines(x,dtawide[5,2:ncol(dtawide)],lty=4,lwd=2.5,col=colvec[4])
lines(x,dtawide[6,2:ncol(dtawide)],lty=2,lwd=2.5,col=colvec[6])

text(1.1,0.55,"DSP",cex=0.75, col=colvec[3])
text(1.1,1.51,"JCP",cex=0.75, col=colvec[1])
text(1.1,1.19  ,"JSP", cex=0.75, col=colvec[2])
text(1.1,0.15  ,"LDP", cex=0.75, col=colvec[5])
text(2.3,0.6, "CGP", cex=0.75, col=colvec[4])
text(4.05,-0.33,"NLC", cex=0.75, col=colvec[6])
dev.off()

#calculate range between LDP and JSP over time
for.range<- dtawide[3,2:ncol(dtawide)]-dtawide[4,2:ncol(dtawide)]

#################################################################
#################################################################


dta<-read.csv("econ_10Aug09_documents.csv", sep=" ", header=T)

names<-strsplit(rownames(dta),"\\.")

party <- rep(0,length=names)
year<- rep(0,length=names)

for (i in 1:length(names)) {
      party[i]<-names[[i]][1]
      year[i] <-names[[i]][2]
}

dtalong <- cbind(party,year,dta)
attach(dtalong)
dtalong <- dtalong[,-c(4)]

dtawide<-reshape(dtalong,v.names="omega",idvar="party",direction="wide",timevar="year")

x<-seq(1,8,1)
y<-seq(-1.5,2.1,length.out=8)

xlab<-c("60-64","65-69","71-72","76-79","80-83","86-90","93-95","96-98")

pdf("Econ_10Aug09.pdf")
plot(x,y,type="n",main="Economic Policy", xlab="Years", ylab="Party Position", xaxt="n")
axis(1,at=x,labels=xlab)
lines(x,dtawide[1,2:ncol(dtawide)],lty=3,lwd=2.5,col=colvec[3])
lines(x,dtawide[2,2:ncol(dtawide)],lty=1,lwd=2.5,col=colvec[1])
lines(x,dtawide[3,2:ncol(dtawide)],lty=2,lwd=2.5,col=colvec[2])
lines(x,dtawide[4,2:ncol(dtawide)],lty=1,lwd=2.5,col=colvec[5])
lines(x,dtawide[5,2:ncol(dtawide)],lty=4,lwd=2.5,col=colvec[4])
lines(x,dtawide[6,2:ncol(dtawide)],lty=2,lwd=2.5,col=colvec[6])

text(1.1,1.52,"DSP",cex=0.75, col=colvec[3])
text(1.1,1.95,"JCP",cex=0.75, col=colvec[1])
text(1.1,1.22  ,"JSP", cex=0.75, col=colvec[2])
text(1.1,0.68  ,"LDP", cex=0.75, col=colvec[5])
text(2.1,1.12, "CGP", cex=0.75, col=colvec[4])
text(4.1,-0.44,"NLC", cex=0.75, col=colvec[6])
dev.off()

#calculate range between LDP and JSP over time
econ.range<- dtawide[3,2:ncol(dtawide)]-dtawide[4,2:ncol(dtawide)]

#################################################################
#################################################################

dta<-read.csv("domsoc_10Aug09_documents.csv", sep=" ", header=T)

names<-strsplit(rownames(dta),"\\.")

party <- rep(0,length=names)
year<- rep(0,length=names)

for (i in 1:length(names)) {
      party[i]<-names[[i]][1]
      year[i] <-names[[i]][2]
}

dtalong <- cbind(party,year,dta)
attach(dtalong)
dtalong <- dtalong[,-c(4)]

dtawide<-reshape(dtalong,v.names="omega",idvar="party",direction="wide",timevar="year")

x<-seq(1,8,1)
y<-seq(-1.5,2.1,length.out=8)

xlab<-c("60-64","65-69","71-72","76-79","80-83","86-90","93-95","96-98")

pdf("Domsoc_10Aug09.pdf")
plot(x,y,type="n",main="Domestic/Social Policy", xlab="Years", ylab="Party Position", xaxt="n")
axis(1,at=x,labels=xlab)
lines(x,dtawide[1,2:ncol(dtawide)],lty=3,lwd=2.5,col=colvec[3])
lines(x,dtawide[2,2:ncol(dtawide)],lty=1,lwd=2.5,col=colvec[1])
lines(x,dtawide[3,2:ncol(dtawide)],lty=2,lwd=2.5,col=colvec[2])
lines(x,dtawide[4,2:ncol(dtawide)],lty=1,lwd=2.5,col=colvec[5])
lines(x,dtawide[5,2:ncol(dtawide)],lty=4,lwd=2.5,col=colvec[4])
lines(x,dtawide[6,2:ncol(dtawide)],lty=2,lwd=2.5,col=colvec[6])

text(1.1,1.52,"DSP",cex=0.75, col=colvec[3])
text(1.1,1.74,"JCP",cex=0.75, col=colvec[1])
text(1.1,1.18  ,"JSP", cex=0.75, col=colvec[2])
text(1.1,0.75  ,"LDP", cex=0.75, col=colvec[5])
text(2.1,1.49, "CGP", cex=0.75, col=colvec[4])
text(4.1,-0.48,"NLC", cex=0.75, col=colvec[6])
dev.off()

#calculate range between LDP and JSP over time
domsoc.range<- dtawide[3,2:ncol(dtawide)]-dtawide[4,2:ncol(dtawide)]


#################################################################
#################################################################



yrange<-seq(-0.1, 1.55, length.out=8)

pdf("Range_10Aug09.pdf")
plot(x,yrange,type="n",main="Position Range: LDP - JSP", xlab="Years", ylab="Distance: JSP - LDP", xaxt="n")
axis(1,at=x,labels=xlab)
lines(x,for.range, col="red")
lines(x,econ.range, col = "blue")
lines(x,domsoc.range, col = "green")

text(1.35,0.88,"Foreign", col = "red", cex= 0.75)
text(2.2,0.25,"Domestic/Social", col = "green", cex=0.75)
text(1.35,0.54,"Economy", col = "blue", cex=0.75)
dev.off()


#################################################################
#################################################################














#################################################################
#################################################################
dta<-read.csv("for_10Aug09_documents_95_ci.csv", sep=" ", header=T)

names<-strsplit(rownames(dta),"\\.")

party <- rep(0,length=names)
year<- rep(0,length=names)

for (i in 1:length(names)) {
      party[i]<-names[[i]][1]
      year[i] <-names[[i]][2]
}

dtalong <- cbind(party,year,dta)

dtaLB <- dtalong[,-c(4,5,6)]
dtaLB<-reshape(dtaLB,v.names="LB",idvar="party",direction="wide",timevar="year")

dtaUB <- dtalong[,-c(3,5,6)]
dtaUB<-reshape(dtaUB,v.names="UB",idvar="party",direction="wide",timevar="year")

dtaML <- dtalong[,-c(3,4,6)]
dtaML<-reshape(dtaML,v.names="Omega..ML",idvar="party",direction="wide",timevar="year")


x<-seq(1,8,1)
y<-seq(-1.5,1.5,length.out=8)

xlab<-c("60-64","65-69","71-72","76-79","80-83","86-90","93-95","96-98")

colvec<-rainbow(n=6,start=0.7,end=0.15)


pdf("Foreign_ci_12Aug09.pdf")
plot(x,y,type="n",main="Wordfish Foreign Policy\nLDP and JSP in Comparison", xlab="Years", ylab="Party Position", xaxt="n")
axis(1,at=x,labels=xlab)
y1<-as.vector(dtaLB[3,2:9],mode="numeric")
y2<-as.vector(dtaUB[3,2:9],mode="numeric")
y3<-as.vector(dtaLB[4,2:9],mode="numeric")
y4<-as.vector(dtaUB[4,2:9],mode="numeric")


segments(x,y1,x,y2,lty=1, lwd=2.5, col=colvec[2])
segments(x-0.1,y1,x+0.1,y1,lty=1, lwd=2.5, col=colvec[2])
segments(x-0.1,y2,x+0.1,y2,lty=1, lwd=2.5, col=colvec[2])
segments(x,y3,x,y4,lty=1, lwd=2.5, col=colvec[5])
segments(x-0.1,y3,x+0.1,y3,lty=1, lwd=2.5, col=colvec[5])
segments(x-0.1,y4,x+0.1,y4,lty=1, lwd=2.5, col=colvec[5])

lines(x,dtaML[3,2:9],lty=2,lwd=2.5,col=colvec[2])
lines(x,dtaML[4,2:9],lty=1,lwd=2.5,col=colvec[5])

text(1.2,0.9  ,"JSP", cex=0.75, col=colvec[2])
text(1.2,-0.25,"LDP", cex=0.75, col=colvec[5])
dev.off()


#################################################################
#################################################################
dta<-read.csv("econ_10Aug09_documents_95_ci.csv", sep=" ", header=T)

names<-strsplit(rownames(dta),"\\.")

party <- rep(0,length=names)
year<- rep(0,length=names)

for (i in 1:length(names)) {
      party[i]<-names[[i]][1]
      year[i] <-names[[i]][2]
}

dtalong <- cbind(party,year,dta)

dtaLB <- dtalong[,-c(4,5,6)]
dtaLB<-reshape(dtaLB,v.names="LB",idvar="party",direction="wide",timevar="year")

dtaUB <- dtalong[,-c(3,5,6)]
dtaUB<-reshape(dtaUB,v.names="UB",idvar="party",direction="wide",timevar="year")

dtaML <- dtalong[,-c(3,4,6)]
dtaML<-reshape(dtaML,v.names="Omega..ML",idvar="party",direction="wide",timevar="year")


x<-seq(1,8,1)
y<-seq(-1.5,1.5,length.out=8)

xlab<-c("60-64","65-69","71-72","76-79","80-83","86-90","93-95","96-98")

colvec<-rainbow(n=6,start=0.7,end=0.15)


pdf("Econ_ci_12Aug09.pdf")
plot(x,y,type="n",main="Wordfish Economic Policy\nLDP and JSP in Comparison", xlab="Years", ylab="Party Position", xaxt="n")
axis(1,at=x,labels=xlab)
y1<-as.vector(dtaLB[3,2:9],mode="numeric")
y2<-as.vector(dtaUB[3,2:9],mode="numeric")
y3<-as.vector(dtaLB[4,2:9],mode="numeric")
y4<-as.vector(dtaUB[4,2:9],mode="numeric")


segments(x,y1,x,y2,lty=1, lwd=2.5, col=colvec[2])
segments(x-0.1,y1,x+0.1,y1,lty=1, lwd=2.5, col=colvec[2])
segments(x-0.1,y2,x+0.1,y2,lty=1, lwd=2.5, col=colvec[2])
segments(x,y3,x,y4,lty=1, lwd=2.5, col=colvec[5])
segments(x-0.1,y3,x+0.1,y3,lty=1, lwd=2.5, col=colvec[5])
segments(x-0.1,y4,x+0.1,y4,lty=1, lwd=2.5, col=colvec[5])

lines(x,dtaML[3,2:9],lty=2,lwd=2.5,col=colvec[2])
lines(x,dtaML[4,2:9],lty=1,lwd=2.5,col=colvec[5])

text(1.4,1.5  ,"JSP", cex=0.75, col=colvec[2])
text(1.4,0.6,"LDP", cex=0.75, col=colvec[5])
dev.off()

#################################################################
#################################################################
dta<-read.csv("domsoc_10Aug09_documents_95_ci.csv", sep=" ", header=T)

names<-strsplit(rownames(dta),"\\.")

party <- rep(0,length=names)
year<- rep(0,length=names)

for (i in 1:length(names)) {
      party[i]<-names[[i]][1]
      year[i] <-names[[i]][2]
}

dtalong <- cbind(party,year,dta)

dtaLB <- dtalong[,-c(4,5,6)]
dtaLB<-reshape(dtaLB,v.names="LB",idvar="party",direction="wide",timevar="year")

dtaUB <- dtalong[,-c(3,5,6)]
dtaUB<-reshape(dtaUB,v.names="UB",idvar="party",direction="wide",timevar="year")

dtaML <- dtalong[,-c(3,4,6)]
dtaML<-reshape(dtaML,v.names="Omega..ML",idvar="party",direction="wide",timevar="year")


x<-seq(1,8,1)
y<-seq(-1.5,1.6,length.out=8)

xlab<-c("60-64","65-69","71-72","76-79","80-83","86-90","93-95","96-98")

colvec<-rainbow(n=6,start=0.7,end=0.15)


pdf("DomSoc_ci_12Aug09.pdf")
plot(x,y,type="n",main="Wordfish Domestic-Social Policy\nLDP and JSP in Comparison", xlab="Years", ylab="Party Position", xaxt="n")
axis(1,at=x,labels=xlab)
y1<-as.vector(dtaLB[3,2:9],mode="numeric")
y2<-as.vector(dtaUB[3,2:9],mode="numeric")
y3<-as.vector(dtaLB[4,2:9],mode="numeric")
y4<-as.vector(dtaUB[4,2:9],mode="numeric")


segments(x,y1,x,y2,lty=1, lwd=2.5, col=colvec[2])
segments(x-0.1,y1,x+0.1,y1,lty=1, lwd=2.5, col=colvec[2])
segments(x-0.1,y2,x+0.1,y2,lty=1, lwd=2.5, col=colvec[2])
segments(x,y3,x,y4,lty=1, lwd=2.5, col=colvec[5])
segments(x-0.1,y3,x+0.1,y3,lty=1, lwd=2.5, col=colvec[5])
segments(x-0.1,y4,x+0.1,y4,lty=1, lwd=2.5, col=colvec[5])

lines(x,dtaML[3,2:9],lty=2,lwd=2.5,col=colvec[2])
lines(x,dtaML[4,2:9],lty=1,lwd=2.5,col=colvec[5])

text(1.4,1.41  ,"JSP", cex=0.75, col=colvec[2])
text(1.4,0.75,"LDP", cex=0.75, col=colvec[5])
dev.off()









